//
//  VisitorTableViewController.swift
//  Weibo
//
//  Created by 李振兴 on 15/10/15.
//  Copyright © 2015年 李振兴. All rights reserved.
//

import UIKit

class VisitorTableViewController: UITableViewController {
    /// 用户登录标记
    private var userLogon = UserAccountViewModel.sharedUserAccount.isLogon
    
    var visitorView:VisitorView?
    
    override func viewDidLoad() {
        print("viewDidload")
        super.viewDidLoad()
        
    }
    override func loadView() {
        print("loadView")
        userLogon ? super.loadView() : setupVisitorView()
       
    }
    
    private func setupVisitorView(){
        
        visitorView=VisitorView()
        
        //visitorView?.delegate = self
        visitorView?.registerButton.addTarget(self, action: "visitorViewDidRegister", forControlEvents: UIControlEvents.TouchUpInside)
        visitorView?.loginButton.addTarget(self, action: "visitorViewDidLogin", forControlEvents: UIControlEvents.TouchUpInside)
        view = visitorView
        
        
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", style: .Plain, target: self, action: "visitorViewDidRegister")
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登录", style: .Plain, target: self, action: "visitorViewDidLogin")
    }
    

  }
//extension VisitorTableViewController:VisitorViewDelegate{
//    func visitorViewDidRegister() {
//        print("注册")
//    }
//    func visitorViewDidLogin() {
//        print("登录")
//    }
//}
//MARK:添加监听
extension VisitorTableViewController{
    func visitorViewDidRegister() {
        print("注册")
    }
    func visitorViewDidLogin() {
        print("登录")
        let vc = OAuthViewController()
        let nav = UINavigationController(rootViewController: vc)
        presentViewController(nav, animated: true, completion: nil)
        
    }
}


